package com.killers.cold.config;

import liquibase.integration.spring.SpringLiquibase;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.DefaultResourceLoader;

import javax.sql.DataSource;

/**
 * @author 罗天豪
 * @date 2019/9/4
 */
@Configuration
public class LiquibaseConfiguration {

    /**
     * 1.指定Spring-boot运行Liquibase
     * 2.如果以后有新的业务模块，就指定新的业务changeLog位置。
     * @param dataSource 数据源
     * @return 自动运行的liquibase
     */
    @Bean
    public SpringLiquibase fileLiquibase(DataSource dataSource) {
        SpringLiquibase liquibase = new SpringLiquibase();

        liquibase.setChangeLog("classpath:liquibase/file/master.xml");
        liquibase.setDataSource(dataSource);
        liquibase.setShouldRun(true);
        liquibase.setResourceLoader(new DefaultResourceLoader());

        liquibase.setDatabaseChangeLogTable("file_changelog_table");
        liquibase.setDatabaseChangeLogLockTable("file_changelog_lock_table");
        return liquibase;
    }
}
